<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template match="/">
		<html>
			<head>
				<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
			</head>
			<body>
				<h2>Report for test suite <xsl:value-of select="@id"/></h2>
				<p><xsl:value-of select="@description"/></p>
				<table border="1">
					<thead>
						<tr bgcolor="grey">
							<th>Scenario's ID:</th>
							<th>Scenario's Result:</th>
							<th>Scenario's Details:</th>
						</tr>
					</thead>
					<tbody>
						<xsl:for-each select="TestSuite/Scenarios/Scenario">
							<xsl:element name="tr">
								<xsl:attribute name="id">scenario<xsl:value-of
									select="position()" />
                            </xsl:attribute>
								<td>
									<xsl:value-of select="@id" />
								</td>
								<xsl:choose>
									<xsl:when test="ScenarioExecutionEndExecEvent[@executionResult='end']">
										<td bgcolor="#00CC33">OK</td>
									</xsl:when>
									<xsl:when test="*[last()][@executionResult]='error'">
										<td bgcolor="#D00000">ERROR</td>
									</xsl:when>
									<xsl:otherwise>
										<td bgcolor="yellow">UNKNOWN</td>
									</xsl:otherwise>
								</xsl:choose>
								<td>
									<xsl:element name="a">
										<xsl:attribute name="id">scenario<xsl:value-of
											select="position()" />-click</xsl:attribute>
										<xsl:attribute name="href">#</xsl:attribute>
										show details
									</xsl:element>
									<xsl:element name="div">
										<xsl:attribute name="id">scenario<xsl:value-of
											select="position()" />-details</xsl:attribute>
										
										
							<!-- 
							Details of scenario start here. 
							-->
							
										<xsl:for-each select="*">
										<p>
										  <xsl:choose>
										      <xsl:when test="local-name()='ScenarioExecutionStartExecEvent'">
										          Started at <xsl:value-of select="@eventDate"/>. <xsl:value-of select="@eventDescription"/>
										      </xsl:when>
                                              <xsl:when test="local-name()='IfConditionEvaluationStartExecEvent'">
                                                  <xsl:value-of select="@eventDate"/>. <xsl:value-of select="@eventDescription"/> <xsl:value-of select="@ifDescription"/><br/>
                                                  if (<xsl:value-of select="@left"/> <xsl:value-of select="@operator"/> <xsl:value-of select="@right"/>)
                                              </xsl:when>
                                              <xsl:when test="local-name()='IfConditionEvaluationEndExecEvent'">
                                                  <xsl:value-of select="@eventDate"/>. <xsl:value-of select="@eventDescription"/><br/>
                                                  if (<xsl:value-of select="@evaluatedLeft"/> <xsl:value-of select="@operator"/> <xsl:value-of select="@evaluatedRight"/>) = <xsl:value-of select="@evaluationResult"/>
                                              </xsl:when>
                                              <xsl:when test="local-name()='ElseConditionEvaluationStartExecEvent'">
                                                  <xsl:value-of select="@eventDate"/>. <xsl:value-of select="@eventDescription"/> <xsl:value-of select="@ifDescription"/><br/>
                                                  if (<xsl:value-of select="@left"/> <xsl:value-of select="@operator"/> <xsl:value-of select="@right"/>)
                                              </xsl:when>
                                              <xsl:when test="local-name()='ElseConditionEvaluationEndExecEvent'">
                                                  <xsl:value-of select="@eventDate"/>. <xsl:value-of select="@eventDescription"/><br/>
                                                  if (<xsl:value-of select="@evaluatedLeft"/> <xsl:value-of select="@operator"/> <xsl:value-of select="@evaluatedRight"/>) = <xsl:value-of select="@evaluationResult"/>
                                              </xsl:when>
                                              <xsl:when test="local-name()='DoScenarioStepStartExecEvent'">
                                                  <xsl:value-of select="@eventDate"/>. <xsl:value-of select="@eventDescription"/>. <xsl:value-of select="@stepDescription"/><br/>
                                                  Using URL: <xsl:value-of select="@endpointUrl"/><br/>
                                                  Using request from <xsl:value-of select="@requestPath"/><br/>
                                              </xsl:when>
                                              <xsl:when test="local-name()='JmsMessageSentExecEvent'">
                                                  <xsl:value-of select="@eventDate"/>. <xsl:value-of select="@eventDescription"/><br/>
                                                  <tt><xsl:value-of select="@messageContent"/></tt>
                                              </xsl:when>
                                              <xsl:when test="local-name()='JmsMessageReceivedExecEvent'">
                                                  <xsl:value-of select="@eventDate"/>. <xsl:value-of select="@eventDescription"/><br/>
                                                  <tt><xsl:value-of select="@messageContent"/></tt>
                                              </xsl:when>
                                              <xsl:when test="local-name()='DoScenarioStepEndExecEvent'">
                                                  <xsl:value-of select="@eventDate"/>. <xsl:value-of select="@eventDescription"/>
                                              </xsl:when>
                                              <xsl:when test="local-name()='ScenarioExecutionEndExecEvent'">
                                                  Ended at <xsl:value-of select="@eventDate"/>. <xsl:value-of select="@eventDescription"/><br/>
                                                  <xsl:value-of select="@executionResult"/>
                                              </xsl:when>										
										      <xsl:otherwise>
										          <b style="color: red">Unknown event! Probably it's a bug.</b>
										      </xsl:otherwise>
										
										  </xsl:choose>
										  </p>
										</xsl:for-each>
							<!-- 
                            Details of scenario end here. 
                            -->
                            			
										
									</xsl:element>
								</td>
							</xsl:element>
						</xsl:for-each>
					</tbody>
				</table>
				<!-- 
				    I really don't know WTF is with below <script>a</script>. If there's 
					no content between script tags, this XSLT doesn't work in Declatest. Although 
					it works in plain Firefox or so. 
				-->
				<script type="text/javascript" src="../../../../../res/jquery-1.6.js">a</script>
				<script type="text/javascript" charset="UTF-8">

					$(document).ready(function() {

					<xsl:for-each select="TestSuite/Scenarios/Scenario">
						$('#scenario<xsl:value-of select="position()" />-details').hide(400);

						  $('#scenario<xsl:value-of select="position()" />-click').click(function() {
						  $('#scenario<xsl:value-of select="position()" />-details').toggle(400);
						  return false;
						});
					</xsl:for-each>

					});

				</script>
			</body>
		</html>
	</xsl:template>

</xsl:stylesheet>